package com.heima.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.heima.common.PageResult;
import com.heima.pojo.VendingMachine;
import com.heima.pojo.dto.VendingMachineDto;
import com.heima.pojo.vo.VendingMachineVo;
import com.heima.service.IVendingMachineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xjy
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/vm-service/vm")
@Api(tags = "售货机管理")
public class VendingMachineController {

    @Autowired
    private IVendingMachineService vendingMachineService;

    @GetMapping("/search")
    @ApiOperation("分页查询售货机列表")
    public PageResult<VendingMachineVo> search(PageResult<VendingMachineVo> pageResult, @ApiParam(value = "售货机软编号", required = false) String innerCode) {
        return vendingMachineService.search(pageResult, innerCode);
    }

    @PostMapping
    @ApiOperation("添加售货机")
    public Boolean add(@RequestBody VendingMachineDto vendingMachineDto) {
        if (ObjectUtil.isEmpty(vendingMachineDto)) {
            return false;
        }
        return vendingMachineService.addVendingMachine(vendingMachineDto);
    }
}
